package com.kikoulol.jarmoryextactor;

import java.util.ArrayList;
import java.util.List;

import noNamespace.ArenaTeam;
import noNamespace.PageDocument;

import org.apache.xmlbeans.XmlException;

import com.kikoulol.jarmoryextactor.utils.Utils;

public class Team {

	private String armoryUrl;
	private String partialTeamUrl;
	private String name;
	private String url;
	private String teamUrlEscape;
	private String teamUrl;
	private String teamSize;
	private String size;
	private String seasonGamesWon;
	private String seasonGamesPlayed;
	private String season;
	private String relevance;
	private String realmUrl;
	private String realm;
	private String rating;
	private String ranking;
	private String lastSeasonRanking;
	private String gamesWon;
	private String gamesPlayed;
	private String faction;
	private String created;
	private String battleGroup;
	private List<Character> members;
	private ArenaTeam team;
	

	public Team(String armoryUrl,String partialTeamUrl) throws XmlException, InterruptedException {
		this.armoryUrl = armoryUrl;
		this.partialTeamUrl = partialTeamUrl;
		String xml = null;
		xml = Utils.getArmoryXml(armoryUrl + "team-info.xml?" + partialTeamUrl);
		PageDocument pageDoc = PageDocument.Factory.parse(xml);
		team  = pageDoc.getPage().getTeamInfo().getArenaTeam();
		members = new ArrayList<Character>();
		init(team);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Character> getMembers() throws XmlException, InterruptedException {
		members = new ArrayList<Character>();
		for (noNamespace.Character player : team.getMembers().getCharacterArray()) {
			Character myChar = new Character(armoryUrl, player.getCharUrl());
			addMembre(myChar);
		}
		
		return members;
	}

	public void setMembers(List<Character> members) {
		this.members = members;
	}
	
	public void addMembre(Character character) {
		members.add(character);
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getTeamUrlEscape() {
		return teamUrlEscape;
	}

	public void setTeamUrlEscape(String teamUrlEscape) {
		this.teamUrlEscape = teamUrlEscape;
	}

	public String getTeamUrl() {
		return teamUrl;
	}

	public void setTeamUrl(String teamUrl) {
		this.teamUrl = teamUrl;
	}

	public String getTeamSize() {
		return teamSize;
	}

	public void setTeamSize(String teamSize) {
		this.teamSize = teamSize;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getSeasonGamesWon() {
		return seasonGamesWon;
	}

	public void setSeasonGamesWon(String seasonGamesWon) {
		this.seasonGamesWon = seasonGamesWon;
	}

	public String getSeasonGamesPlayed() {
		return seasonGamesPlayed;
	}

	public void setSeasonGamesPlayed(String seasonGamesPlayed) {
		this.seasonGamesPlayed = seasonGamesPlayed;
	}

	public String getSeason() {
		return season;
	}

	public void setSeason(String season) {
		this.season = season;
	}

	public String getRelevance() {
		return relevance;
	}

	public void setRelevance(String relevance) {
		this.relevance = relevance;
	}

	public String getRealmUrl() {
		return realmUrl;
	}

	public void setRealmUrl(String realmUrl) {
		this.realmUrl = realmUrl;
	}

	public String getRealm() {
		return realm;
	}

	public void setRealm(String realm) {
		this.realm = realm;
	}

	public String getRating() {
		return rating;
	}

	public void setRating(String rating) {
		this.rating = rating;
	}

	public String getRanking() {
		return ranking;
	}

	public void setRanking(String ranking) {
		this.ranking = ranking;
	}

	public String getLastSeasonRanking() {
		return lastSeasonRanking;
	}

	public void setLastSeasonRanking(String lastSeasonRanking) {
		this.lastSeasonRanking = lastSeasonRanking;
	}

	public String getGamesWon() {
		return gamesWon;
	}

	public void setGamesWon(String gamesWon) {
		this.gamesWon = gamesWon;
	}

	public String getGamesPlayed() {
		return gamesPlayed;
	}

	public void setGamesPlayed(String gamesPlayed) {
		this.gamesPlayed = gamesPlayed;
	}

	public String getFaction() {
		return faction;
	}

	public void setFaction(String faction) {
		this.faction = faction;
	}

	public String getCreated() {
		return created;
	}

	public void setCreated(String created) {
		this.created = created;
	}

	public String getBattleGroup() {
		return battleGroup;
	}

	public void setBattleGroup(String battleGroup) {
		this.battleGroup = battleGroup;
	}

	private void init(ArenaTeam team) throws XmlException, InterruptedException {
		setName(team.getName());
		setBattleGroup(team.getBattleGroup());
		setCreated(team.getCreated());
		setFaction(team.getFaction());
		setGamesPlayed(team.getGamesPlayed());
		setGamesWon(team.getGamesWon());
		setLastSeasonRanking(team.getLastSeasonRanking());
		setRanking(team.getRanking());
		setRating(team.getRating());
		setRealm(team.getRealm());
		setRealmUrl(team.getRealmUrl());
		setRelevance(team.getRelevance());
		setSeason(team.getSeason());
		setSeasonGamesPlayed(team.getSeasonGamesPlayed());
		setSeasonGamesWon(team.getSeasonGamesWon());
		setSize(team.getSize());
		setTeamSize(team.getTeamSize());
		setTeamUrl(team.getTeamUrl());
		setTeamUrlEscape(team.getTeamUrlEscape());
		setUrl(team.getUrl());
		
		//Add members
		/*
		int lol = team.getMembers().getCharacterArray().length;
		for (noNamespace.Character player : team.getMembers().getCharacterArray()) {
			Character myChar = new Character(armoryUrl, player.getCharUrl());
			addMembre(myChar);
		}
		*/
		
	}


}
